package com.itlong.cloud.controller.current;

import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.core.type.TypeReference;
import com.itlong.cloud.POJO.DTO.app.*;
import com.itlong.cloud.POJO.DTO.common.NettyServiceDTO;
import com.itlong.cloud.POJO.DTO.common.ParkingMessageDTO;
import com.itlong.cloud.POJO.DTO.common.ResultMessageDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyProjectGetPropertyInfoDTO;
import com.itlong.cloud.POJO.PO.AppTempSaveMessagePO;
import com.itlong.cloud.POJO.PO.PropertyParkCouponPO;
import com.itlong.cloud.POJO.PO.RepairProcessPO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.app.*;
import com.itlong.cloud.POJO.VO.operate.OperateAdImgVO;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.annotation.LoggerInfo;
import com.itlong.cloud.common.network.tcp.netty.INettyServiceClient;
import com.itlong.cloud.constants.LogDescConstant;
import com.itlong.cloud.constants.RedisConstant;
import com.itlong.cloud.enumerate.FileCatalogEnum;
import com.itlong.cloud.enumerate.LanguageTypeEnum;
import com.itlong.cloud.enumerate.ParkingOrderTypeEnum;
import com.itlong.cloud.enumerate.PropertyInfoTypeEnum;
import com.itlong.cloud.enumerate.ecode.AppErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.ErrorCode;
import com.itlong.cloud.enumerate.ecode_en.AppErrorCodeEnumEN;
import com.itlong.cloud.enumerate.ecode_en.BaseErrorCodeEnumEN;
import com.itlong.cloud.equip.property.IPropertyConsumptionServiceClient;
import com.itlong.cloud.noncore.property.IPropertyRepairManageClient;
import com.itlong.cloud.paymenthub.IAppCarPaymentDetailServiceClient;
import com.itlong.cloud.paymenthub.IPropertyMealManageServiceClient;
import com.itlong.cloud.paymenthub.IPropertyPaymentServiceClient;
import com.itlong.cloud.paymenthub.IWeChatPayServiceClient;
import com.itlong.cloud.project.app.IAppMonthCardParkingServiceClient;
import com.itlong.cloud.project.app.IAppRoomServiceClient;
import com.itlong.cloud.project.operate.IOperateAdManageServiceClient;
import com.itlong.cloud.project.operate.IOperatePushInfoServiceClient;
import com.itlong.cloud.project.property.*;
import com.itlong.cloud.service.RedisService;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.user.app.*;
import com.itlong.cloud.user.property.IPropertyUserServiceClient;
import com.itlong.cloud.utils.encrypt.Md5EncryptUtil;
import com.itlong.cloud.utils.encrypt.UserTokenUtil;
import com.itlong.cloud.utils.file.UploadFileUtil;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.node.JsonUtil;
import com.itlong.cloud.utils.page.Page;
import com.itlong.cloud.utils.words.NumberHandlerUtil;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import sun.misc.BASE64Decoder;

import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <desc>
 *     新版APP的服务版块控制器
 * </desc>
 * @create  2017/9/19
 */

@RestController
@RequestMapping("/service")
@RefreshScope
public class AppServeController extends BaseController{
    private static final Logger LOG = LoggerFactory.getLogger(AppServeController.class);

    @Value("${" + PlatformConstants.FILE_FTP_HOST + "}")
    public String FILE_FTP_HOST;
    @Value("${" + PlatformConstants.FILE_FTP_PORT + "}")
    public String FILE_FTP_PORT;
    @Value("${" + PlatformConstants.FILE_FTP_USERNAME + "}")
    public String FILE_FTP_USERNAME;
    @Value("${" + PlatformConstants.FILE_FTP_PASSWORD + "}")
    public String FILE_FTP_PASSWORD;
    @Value("${" + PlatformConstants.FILE_ACCESS_URL + "}")
    public String FILE_ACCESS_URL;

    @Value("${" + PlatformConstants.APP_REQUEST_PARAMS_ENCRYPT_KEY + "}")
    public String APP_REQUEST_PARAMS_ENCRYPT_KEY;

    @Value("${" + PlatformConstants.PROPERTYMANAGE_WEB_URL + "}")
    public String PROPERTY_MANAGE_WEB_URL;

    @Value("${" + PlatformConstants.APP_USER_TOKEN_KEY + "}")
    public String APP_USER_TOKEN_KEY;

    @Autowired
    IAppUserInfoCacheServiceClient userCache;
    @Autowired
    IAppServeServiceClient iAppServeServiceClient;
    @Autowired
    IOperateAdManageServiceClient iOperateAdManageServiceClient;
    @Autowired
    IOperatePushInfoServiceClient iOperatePushInfoServiceClient;
    @Autowired
    IPropertyPropertyInfoServiceClient iPropertyPropertyInfoServiceClient;
    @Autowired
    IAppMineServiceClient iAppMineServiceClient;
    @Autowired
    private IPropertyRepairManageClient iPropertyRepairManageClient;
    @Autowired
    private RedisService redisService;
    @Autowired
    IPropertyAccountServiceClient iPropertyAccountServiceClient;
    @Autowired
    private IPropertyUserServiceClient iPropertyUserServiceClient;

    @Autowired
    IAppMonthCardParkingServiceClient iAppMonthCardParkingServiceClient;

    @Autowired
    IPropertyCarMonthCardServiceClient iPropertyCarMonthCardServiceClient;

    @Autowired
    IAppCouponServiceClient iAppCouponServiceClient;

    @Autowired
    IAppParkRecordServiceClient iAppParkRecordServiceClient;

    @Autowired
    IAppCarPaymentDetailServiceClient iAppCarPaymentDetailServiceClient;

    @Autowired
    IWeChatPayServiceClient wechatPayServiceClient;

    @Autowired
    INettyServiceClient iNettyServiceClient;

    @Autowired
    IParkCarHttpServiceClient parkCarHttpServiceClient;

    @Autowired
    IAppRoomServiceClient iAppRoomServiceClient;

    @Autowired
    IPropertyMealManageServiceClient iPropertyMealManageServiceClient;

    @Autowired
    IPropertyRoomInfoServiceClient iPropertyRoomInfoServiceClient;

    @Autowired
    private IPropertyPaymentServiceClient iPropertyPaymentServiceClient;

    @Autowired
    private IPropertyConsumptionServiceClient iPropertyConsumptionServiceClient;


    /**
     * <desc>
     *      上传图片文件
     * <desc/>
     *
     * @param imageStr 图片二进制
     * @param imageType 图片类型
     * @return
     * @author Chunjian.G
     * @createDate 2017-11-10
     */
    private String uploadImageFile(String imageStr,String imageType, FileCatalogEnum fileCatalog){
        try {
            imageStr = URLDecoder.decode(imageStr, "UTF-8");
        }catch (Exception e){
            LOG.info("imageStr URLDecoder失败", e);
            return null;
        }
        byte[] bytes = null;
        try {
            bytes = new BASE64Decoder().decodeBuffer(imageStr);
        } catch (IOException e) {
            LOG.info("BASE64Decoder().decodeBuffer失败,imageStr不合法", e);
            return null;
        }
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        UploadFileUtil.UploadFile uploadFileUtil = new UploadFileUtil().new UploadFile(
                FILE_FTP_HOST,
                FILE_FTP_USERNAME,
                FILE_FTP_PASSWORD,
                FILE_FTP_PORT,
                byteArrayInputStream,
                imageType,
                FILE_ACCESS_URL,
                fileCatalog.getType()
        );
        try {
            //LOG.info("正在上传图片");
            Map<String, Object> resultMap = UploadFileUtil.uploadFile(uploadFileUtil);
            //LOG.info("图片上传完毕");
            String returnCode = resultMap.get("returnCode").toString();
            if ("true".equals(returnCode)){
                String fileUrl = resultMap.get("accessPath").toString();
                return fileUrl;
            }else {
                LOG.info(String.format("图片上传失败，returnCode: %s",returnCode));
                return null;
            }
        } catch (IOException e) {
            LOG.info("UploadFileUtil.uploadFile失败", e);
            return null;
        }
    }

    /**
     * <desc>
     *      获取当前时间某项目允许推送的最新推送消息
     * <desc/>
     *
     * @param projectId 项目id
     * @param type 广告类型（1主页，2服务页，3物业服务页）
     * @param sign 签名
     * @return
     * @author Chunjian.G
     * @createDate 2017-11-08
     */
    @RequestMapping(value = "/getBanner",method = RequestMethod.POST)
    @ResponseBody
    public Object getBanner(String projectId, String type,String createTime, String sign,String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                type = request.getAttribute("type") == null ? null : request.getAttribute("type").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验证签名
            Map<String,String> params = new HashMap<>();
            params.put("projectId",projectId);
            params.put("type",type);
            params.put("createTime",createTime);
            params.put("language",language);
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            if (StringUtils.isBlank(projectId)){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PROJECT_ID_EMPTY_ERR.getErrorCode():AppErrorCodeEnumEN.PROJECT_ID_EMPTY_ERR.getErrorCode();
                return  new MessageVO(errorCode);
            }
            Integer bannerType = StringHandlerUtil.strToIntDef(type, 0);
            if (bannerType == 0){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.BANNER_TYPE_INVALID.getErrorCode():AppErrorCodeEnumEN.BANNER_TYPE_INVALID.getErrorCode();
                return  new MessageVO(errorCode);
            }
            List<OperateAdImgVO> adImgVOS = iOperateAdManageServiceClient.getBannerImgs(projectId, bannerType,1);
            List<String> propertyNotice = iOperatePushInfoServiceClient.getLatestPushContent(projectId);
            Map<String, Object> resultMap = new HashMap<>();

            //处理null值
            if (adImgVOS != null && adImgVOS.size()>0) {
                for (OperateAdImgVO img: adImgVOS){
                    StringHandlerUtil.formatString(img);
                }
            }
            if (propertyNotice == null){
                propertyNotice = new ArrayList<>();
            }

            resultMap.put("propertyNotice", propertyNotice);
            resultMap.put("imageAry", adImgVOS);
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode(): BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return new MessageVO(errorCode, resultMap);
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】获取服务页面Banner失败", e);
        }
    }

    /**
     * <desc>
     *      获取物业服务项目链接
     * <desc/>
     *
     * @param projectId 项目id
     * @param sign 参数签名
     * @return
     * @author Chunjian.G
     * @createDate 2017-11-10
     */
    @RequestMapping(value = "/itemUrl", method = RequestMethod.POST)
    @ResponseBody
    public Object getPropertyItemUrl(String projectId, String createTime, String sign, String token,String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //合法性验证
            if (StringUtils.isBlank(projectId)){
                return new MessageVO(AppErrorCodeEnum.PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            //验证签名
            Map<String, String> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("createTime",createTime);
            params.put("language",language);
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }

            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            if (userInfo == null){
                throw new Exception("从缓存中获取用户信息失败");
            }
            //物业服务项目链接
            List<AppServiceItemUrlVO.ItemUrl> itemUrls = new ArrayList<>();
            itemUrls.add(new AppServiceItemUrlVO.ItemUrl("1",
                    PROPERTY_MANAGE_WEB_URL +
                            String.format("easyList?type=1&projectId=%s&userId=%s", projectId, userInfo.getUserId())));
            itemUrls.add(new AppServiceItemUrlVO.ItemUrl("2",
                    PROPERTY_MANAGE_WEB_URL +
                            String.format("easyList?type=2&projectId=%s&userId=%s", projectId, userInfo.getUserId())));

            AppServiceItemUrlVO urlVO = new AppServiceItemUrlVO(itemUrls);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), urlVO);
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】获取物业服务项目链接失败", e);
        }
    }

    /**
     * <desc>
     *      提交物业报修、投诉
     * <desc/>
     *
     * @param repairDTO 物业报修、投诉DTO
     * @return
     * @author Chunjian.G
     * @createDate 2017-11-09
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_POST_REPAIR)
    @RequestMapping(value = "postRepair", method = RequestMethod.POST)
    @ResponseBody
    public Object postRepair(AppServicePostRepairDTO repairDTO){
        try {
            boolean flag1 = StringUtils.isNotBlank(repairDTO.getCreateTime());
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                repairDTO = HttpProtocolUtil.parseRequestParamToDTO(AppServicePostRepairDTO.class, request);
            }
            //合法性判断
            if (null == repairDTO){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (StringUtils.isBlank(repairDTO.getProjectId()) || !repairDTO.getProjectId().matches("[0-9]{8}")){
                return new MessageVO(AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode());
            }
            Integer propertyType = StringHandlerUtil.strToIntDef(repairDTO.getPropertyType(), 0);
            if (propertyType == 0){
                return new MessageVO(AppErrorCodeEnum.PROPERTY_TYPE_INVALID.getErrorCode());
            }
            if (null != repairDTO.getPropertyInfo() && repairDTO.getPropertyInfo().length() > 300){
                return new MessageVO(AppErrorCodeEnum.FEEDBACK_TOO_LONG.getErrorCode());
            }
            List<AppImageDTO> images = null;
            try {
                if (!StringUtils.isBlank(repairDTO.getImages())){
                    images = JSONArray.parseArray(repairDTO.getImages(), AppImageDTO.class);
                }
            }catch (Exception e){
                return new MessageVO(AppErrorCodeEnum.IMAGE_DATA_INVALID.getErrorCode());
            }

            //验证签名
            Map<String, String> params = new HashMap<>();
            params.put("projectId", repairDTO.getProjectId());
            params.put("propertyType",repairDTO.getPropertyType());
            params.put("propertyInfo",repairDTO.getPropertyInfo());
            params.put("createTime",repairDTO.getCreateTime());
            params.put("language",repairDTO.getLanguage());
            if (flag1) {
                params.put("images",repairDTO.getImages());
                if(!Md5EncryptUtil.checkAppSign(params,repairDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,repairDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }

            //上传图片
            String imgUrls = "";
            FileCatalogEnum catalog = FileCatalogEnum.PROPERTYREPAIR_FILE;
            if (propertyType.equals(PropertyInfoTypeEnum.COMPLAIN_INFO.getType())){
                catalog = FileCatalogEnum.FEEDBACK_FILE;
            }
            if (null != images && !images.isEmpty()){
                for (AppImageDTO img : images){
                    String uploadFilePath = uploadImageFile(img.getImageStr(), img.getImageType(), catalog);
                    if (null != uploadFilePath){
                        imgUrls += uploadFilePath + ",";
                    }else {
                        LOG.info("【APP_服务】物业报修/投诉提交 图片上传失败");
                        return new MessageVO(AppErrorCodeEnum.IMAGE_UPLOAD_FAILED.getErrorCode());
                    }
                }
            }
            imgUrls = StringHandlerUtil.trim(imgUrls, ",");

            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(repairDTO.getToken());
            if (userInfo == null){
                throw new Exception("从缓存中获取用户信息失败");
            }

            PropertyProjectGetPropertyInfoDTO save = new PropertyProjectGetPropertyInfoDTO();
            save.setProjectId(repairDTO.getProjectId());
            save.setPropertyType(propertyType);
            save.setPropertyInfo(repairDTO.getPropertyInfo());
            //创建者
            save.setPublisher(userInfo.getUserId());
            //图片url
            save.setImgUrl(imgUrls);

            Integer res = iPropertyPropertyInfoServiceClient.savePropertyInfo(save);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), res);
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】物业报修/投诉提交失败", e);
        }
    }

    /**
     * <desc>
     *      获取投诉记录列表
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/06/17
     */
    @ResponseBody
    @PostMapping("getCompaintList")
    public Object getComplaintList(String projectId, String pageIndex, String token, String createTime, String sign, String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                pageIndex = request.getAttribute("pageIndex") == null ? null : request.getAttribute("pageIndex").toString();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("projectId",projectId);
            params.put("pageIndex",pageIndex);
            params.put("createTime",createTime);
            params.put("language",language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }

            if (StringUtils.isBlank(projectId) || StringUtils.isBlank(pageIndex) || StringUtils.isBlank(token)) {
                return new MessageVO(LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.NOT_PARAM.getErrorCode() : BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode());
            }
            // 从缓存中获取用户信息
            AppUserCacheVO userInfo = (AppUserCacheVO) StringHandlerUtil.formatString(userCache.retrieve(token));
            Map<String, Object> data = iPropertyPropertyInfoServiceClient.getComplaintList(projectId, pageIndex, userInfo.getUserId());
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.SUCCESS.getErrorCode() : BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return new MessageVO(errorCode, data);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务版块】获取用户投诉记录列表失败", e);
        }
    }

    /**
     * <desc>
     *      获取投诉详情
     * </desc>
     *
     * @param msgId 投诉记录ID
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/06/17
     */
    @ResponseBody
    @PostMapping("complaintDetail")
    public Object complaintDetail(String msgId, String createTime, String sign, String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                msgId = request.getAttribute("msgId") == null ? null : request.getAttribute("msgId").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("msgId",msgId);
            params.put("createTime",createTime);
            params.put("language",language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }

            if (StringUtils.isBlank(msgId)) {
                return new MessageVO(LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.NOT_PARAM.getErrorCode() : BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode());
            }
            Map<String, Object> data = iPropertyPropertyInfoServiceClient.getComplaintDetail(msgId);
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.SUCCESS.getErrorCode() : BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return new MessageVO(errorCode, data);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务版块】获取用户投诉记录列表失败", e);
        }
    }

    /**
     * <desc>
     * 保存app端监听linPhone状态的数据
     * <desc/>
     *
     * @param message linPhone状态的数据
     * @return MessageVO 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2018/05/08
     */
    @PostMapping(path = "/saveMessage")
    @ResponseBody
    @AuthAccessRequired
    public Object saveMessage(String message,String phoneNum) {
        try {
            boolean flag1 = StringUtils.isNotBlank(message);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                message = request.getAttribute("message") == null ? null : request.getAttribute("message").toString();
                phoneNum = request.getAttribute("phoneNum") == null ? null : request.getAttribute("phoneNum").toString();
            }
            //合法性判断
            if (StringUtils.isEmpty(message) || StringUtils.isEmpty(phoneNum)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            iAppMineServiceClient.saveMessage(message,phoneNum);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】保存app端监听linPhone状态的数据失败", e);
        }
    }

    /**
     * <desc>
     *  根据时间或手机号查询linPhone状态的数据
     * <desc/>
     *
     * @param findTime 传入查询时间
     * @param phoneNum 传入查询手机号
     * @return MessageVO 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2018/05/08
     */
    @RequestMapping("/findMessageBytime")
    @ResponseBody
    @AuthAccessRequired
    public Object findMessageBytime(String findTime,String phoneNum) {
        try {
            boolean flag1 = StringUtils.isNotBlank(findTime) || StringUtils.isNotBlank(phoneNum);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                findTime = request.getAttribute("findTime") == null ? null : request.getAttribute("findTime").toString();
                phoneNum = request.getAttribute("phoneNum") == null ? null : request.getAttribute("phoneNum").toString();
            }
            List<AppTempSaveMessagePO> appTempSaveMessageList = null;
            if(StringUtils.isEmpty(findTime)){
                findTime = "";
            }
            if(StringUtils.isEmpty(phoneNum)){
                phoneNum = "";
            }

            appTempSaveMessageList = iAppMineServiceClient.findMessageBytime(findTime,phoneNum);
            List<Map<String,Object>> returnList = new ArrayList<>();
            for(AppTempSaveMessagePO saveMessagePO : appTempSaveMessageList){
                Map<String,Object> map = new HashMap<>();
                map.put("id",saveMessagePO.getId());
                map.put("createTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(saveMessagePO.getCreateTime()));
                map.put("message",saveMessagePO.getMessage());
                map.put("phoneNume",saveMessagePO.getPhoneNum());
                returnList.add(map);
            }

            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),returnList);
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】查询日志失败", e);
        }
    }

    /**
     * <desc>
     *       提交物业报修申请
     * </desc>
     *
     * @param appServiceUploadRepairDTO 提交物业报修申请参数
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2018/08/09
     */
    @PostMapping("uploadRepair")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_UPLOAD_REPAIR)
    public Object uploadRepair(APPServiceUploadRepairDTO appServiceUploadRepairDTO){
        try {
            boolean flag1 = StringUtils.isNotBlank(appServiceUploadRepairDTO.getCreateTime());
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                appServiceUploadRepairDTO = HttpProtocolUtil.parseRequestParamToDTO(APPServiceUploadRepairDTO.class, request);
            }
            // 判断各参数的合法性
            if (null == appServiceUploadRepairDTO) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (StringUtils.isBlank(appServiceUploadRepairDTO.getProjectId())
                    || StringUtils.isBlank(appServiceUploadRepairDTO.getContent()) || StringUtils.isBlank(appServiceUploadRepairDTO.getToken())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (!(appServiceUploadRepairDTO.getRepairType() == 1 || appServiceUploadRepairDTO.getRepairType() == 2)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (appServiceUploadRepairDTO.getRepairType() == 1 && StringUtils.isBlank(appServiceUploadRepairDTO.getOrderDate())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("language",appServiceUploadRepairDTO.getLanguage());
            params.put("createTime",appServiceUploadRepairDTO.getCreateTime());
            params.put("roomId",appServiceUploadRepairDTO.getRoomId());
            params.put("repairType",appServiceUploadRepairDTO.getRepairType().toString());
            params.put("projectId",appServiceUploadRepairDTO.getProjectId());
            params.put("content",appServiceUploadRepairDTO.getContent());
            params.put("orderDate",appServiceUploadRepairDTO.getOrderDate());
            if (flag1) {
                params.put("imageAry",appServiceUploadRepairDTO.getImageAry());
                if(!Md5EncryptUtil.checkAppSign(params, appServiceUploadRepairDTO.getSign(), APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params, appServiceUploadRepairDTO.getSign(), APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            // token解密获取用户id
            String userId = UserTokenUtil.newAPPTokenDecrypt(appServiceUploadRepairDTO.getToken(),APP_USER_TOKEN_KEY);
            if (StringUtils.isBlank(userId)) {
                throw new Exception("token解密获取用户id失败");
            }
            appServiceUploadRepairDTO.setAppUserId(userId);
            // 处理上传的图片
            if (StringUtils.isNotBlank(appServiceUploadRepairDTO.getImageAry())) {
                List<AppServiceUploadRepairImgDTO> appServiceUploadRepairImgDTOS =
                        (List<AppServiceUploadRepairImgDTO>) JsonUtil.toListObject(appServiceUploadRepairDTO.getImageAry(), ArrayList.class, AppServiceUploadRepairImgDTO.class);
                String repairPicture = "";
                for (AppServiceUploadRepairImgDTO appServiceUploadRepairImgDTO : appServiceUploadRepairImgDTOS){
                    String imgUrl = this.uploadImageFile(appServiceUploadRepairImgDTO.getImageUrl(), appServiceUploadRepairImgDTO.getImageType(), FileCatalogEnum.PROPERTYREPAIR_FILE);
                    if ("".equals(repairPicture)) {
                        repairPicture += imgUrl;
                    } else {
                        repairPicture += (","+imgUrl);
                    }
                }
                appServiceUploadRepairDTO.setRepairPicture(repairPicture);
            }
            // 获取流水号
            String repairNum = this.getRepairProcessSerialNum(userId, new Date());
            appServiceUploadRepairDTO.setRepairNum(repairNum);

            iPropertyRepairManageClient.uploadRepair(appServiceUploadRepairDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】提交物业报修失败");
        }
    }

    /**
     * <desc>
     *       获取我的物业报修数据
     * </desc>
     *
     * @param appServiceGetRepairListDTO 获取我的物业报修数据请求参数
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2018/08/10
     */
    @PostMapping("repairList")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_GET_REPAIR_LIST)
    public Object getRepairList(APPServiceGetRepairListDTO appServiceGetRepairListDTO){
        try {
            boolean flag1 = StringUtils.isNotBlank(appServiceGetRepairListDTO.getCreateTime());
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                appServiceGetRepairListDTO = HttpProtocolUtil.parseRequestParamToDTO(APPServiceGetRepairListDTO.class, request);
            }
            if (appServiceGetRepairListDTO == null) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (!NumberHandlerUtil.isInRange(appServiceGetRepairListDTO.getRepairState(), 1, 4)) {
                return new MessageVO(AppErrorCodeEnum.REPAIR_STATUS_ERR.getErrorCode());
            }
            if (StringUtils.isBlank(appServiceGetRepairListDTO.getProjectId())){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (appServiceGetRepairListDTO.getPageNum() == null || StringUtils.isBlank(appServiceGetRepairListDTO.getPageNum().toString())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("language",appServiceGetRepairListDTO.getLanguage());
            params.put("createTime",appServiceGetRepairListDTO.getCreateTime());
            params.put("repairState",appServiceGetRepairListDTO.getRepairState().toString());
            params.put("projectId",appServiceGetRepairListDTO.getProjectId());
            params.put("pageNum",appServiceGetRepairListDTO.getPageNum().toString());
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params, appServiceGetRepairListDTO.getSign(), APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params, appServiceGetRepairListDTO.getSign(), APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            // token解密获取用户id
            String userId = UserTokenUtil.newAPPTokenDecrypt(appServiceGetRepairListDTO.getToken(),APP_USER_TOKEN_KEY);
            if (StringUtils.isBlank(userId)) {
                throw new Exception("token解密获取用户id失败");
            }
            appServiceGetRepairListDTO.setAppUserId(userId);
            appServiceGetRepairListDTO.setPageIndex((appServiceGetRepairListDTO.getPageNum() - 1) * 10);
            List<RepairProcessPO> repairProcessPOS = iPropertyRepairManageClient.getRepairList(appServiceGetRepairListDTO);
            List<AppGetRepairListVO> appGetRepairListVOS = new ArrayList<>();
            Date nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
            for (RepairProcessPO repairProcessPO : repairProcessPOS){
                AppGetRepairListVO appGetRepairListVO = new AppGetRepairListVO();
                appGetRepairListVO.setTitle(repairProcessPO.getRepairType() == 1? "个人设施报修":"公共设施报修");
                appGetRepairListVO.setContent(repairProcessPO.getRepairDescription());
                appGetRepairListVO.setMessageId(repairProcessPO.getRepairId());
                appGetRepairListVO.setBillsId(repairProcessPO.getFeeId());
                appGetRepairListVO.setPropertyName(iPropertyUserServiceClient.getPropertyNameByProjectId(repairProcessPO.getProjectId()));
                switch (repairProcessPO.getRepairStatus()){
                    case 1:
                        appGetRepairListVO.setDate(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(repairProcessPO.getRepairTime()));
                        appGetRepairListVO.setManagerType("1");
                        appGetRepairListVO.setAbleType("1,1,1,1,1");
                        break;
                    case 2:
                        appGetRepairListVO.setDate(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(repairProcessPO.getAcceptTime()));
                        if (repairProcessPO.getRepairType() == 1){
                            appGetRepairListVO.setManagerType("2,3");
                            if (repairProcessPO.getAcceptStatus() == 2) {
                                appGetRepairListVO.setAbleType("1,0,0,1,1");
                            } else if (repairProcessPO.getReworkStatus() == 1) {
                                appGetRepairListVO.setAbleType("1,1,0,1,1");
                            } else {
                                appGetRepairListVO.setAbleType("1,1,1,1,1");
                            }
                        } else {
                            appGetRepairListVO.setManagerType("2");
                            if (repairProcessPO.getAcceptStatus() == 2) {
                                appGetRepairListVO.setAbleType("1,0,1,1,1");
                            } else {
                                appGetRepairListVO.setAbleType("1,1,1,1,1");
                            }
                        }
                        break;
                    case 3:
                        appGetRepairListVO.setDate(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(repairProcessPO.getCompleteTime()));
                        if (repairProcessPO.getRepairType() == 1){
                            appGetRepairListVO.setManagerType("4");
                            Date completeTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(repairProcessPO.getCompleteTime()));
                            long betweenDate = (nowTime.getTime() - completeTime.getTime()) / (1000 * 60 * 60 * 24);
                            if ((repairProcessPO.getReworkStatus() == 1 && repairProcessPO.getReworkYet() == 0) || betweenDate > 6) {//完成时间7天后不能再申请返修
                                appGetRepairListVO.setAbleType("1,1,1,0,1");
                            } else {
                                appGetRepairListVO.setAbleType("1,1,1,1,1");
                            }
                        } else {
                            appGetRepairListVO.setManagerType("");
                            appGetRepairListVO.setAbleType("1,1,1,1,1");
                        }
                        break;
                    case 4:
                        appGetRepairListVO.setDate(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(repairProcessPO.getCancelTime()));
                        appGetRepairListVO.setManagerType("5");
                        appGetRepairListVO.setAbleType("1,1,1,1,1");
                        break;
                    default:
                        break;
                }
                appGetRepairListVOS.add((AppGetRepairListVO) StringHandlerUtil.formatString(appGetRepairListVO));
            }

            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),appGetRepairListVOS);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取我的物业报修数据失败", e);
        }
    }

    /**
     * <desc>
     *       获取我的报修详情
     * </desc>
     *
     * @param messageId 报修数据id
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2018/08/10
     */
    @PostMapping("repairDetail")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_GET_REPAIR_DETAIL)
    public Object repairDetail(String messageId,String token,String sign,String language,String createTime){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                messageId = request.getAttribute("messageId") == null ? null : request.getAttribute("messageId").toString();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            if (StringUtils.isBlank(messageId)) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("language",language);
            params.put("createTime",createTime);
            params.put("messageId",messageId);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            AppRepairDetailVO appRepairDetailVO = iPropertyRepairManageClient.getRepairDetail(messageId);
            AppRepairDetailVO data = (AppRepairDetailVO) StringHandlerUtil.formatString(appRepairDetailVO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),data);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取我的报修详情失败");
        }
    }

    /**
     * <desc>
     *       操作报修数据
     * </desc>
     *
     * @param messageId 报修数据id
     * @param managerType 操作类型
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2018/08/13
     */
    @PostMapping("repairManager")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_REPAIR_MANAGER)
    public Object repairManager(String messageId,String managerType,String token,String sign,String language,String createTime){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                messageId = request.getAttribute("messageId") == null ? null : request.getAttribute("messageId").toString();
                managerType = request.getAttribute("managerType") == null ? null : request.getAttribute("managerType").toString();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            if (StringUtils.isBlank(messageId) || StringUtils.isBlank(managerType)) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode(),(Object) managerType);
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("language",language);
            params.put("createTime",createTime);
            params.put("messageId",messageId);
            params.put("managerType",managerType);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode,(Object) managerType);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode,(Object) managerType);
                }
            }
            if (!("1".equals(managerType) || "2".equals(managerType) || "4".equals(managerType) || "5".equals(managerType))) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode(),(Object) managerType);
            }
            Integer intRes = iPropertyRepairManageClient.repairManager(messageId, managerType);
            AppRepairManagerVO appRepairManagerVO = new AppRepairManagerVO();
            appRepairManagerVO.setManagerType(managerType);
            appRepairManagerVO.setAbleType("1,1,1,1,1");
            if (intRes == -1) {
                return new MessageVO(AppErrorCodeEnum.REPAIR_STATUS_HAS_MODIFIED.getErrorCode(),appRepairManagerVO);
            }
            if (intRes == 0) {
                return new MessageVO(BaseErrorCodeEnum.ERROR.getErrorCode(),appRepairManagerVO);
            }
            if ("2".equals(managerType)) {
                appRepairManagerVO.setAbleType("1,0,0,1,1");
            }
            if ("4".equals(managerType)) {
                appRepairManagerVO.setAbleType("1,1,1,0,1");
            }
            appRepairManagerVO = (AppRepairManagerVO) StringHandlerUtil.formatString(appRepairManagerVO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),appRepairManagerVO);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】操作报修数据失败");
        }
    }

    /**
     * <desc>
     *      获取物业报修流水号，规避并发情况
     * </desc>
     *
     * @param userId 当前用户id
     * @return 流水号
     * @author wangzhi
     * @createDate 2018/08/09
     */
    private String getRepairProcessSerialNum(String userId, Date nowTime) throws Exception{
        String repairNum;
        String timeNum = new SimpleDateFormat("yyMMdd").format(nowTime);
        String key = RedisConstant.REPAIR_SERIAL_NUM + timeNum;
        // 获取当前可用的流水号
        String value = redisService.get(key);
        // 规避并发情况
        if (StringUtils.isBlank(value)) { // 缓存中还没有今天的流水号
            // 要考虑缓存被非法清除的因素，value为空则去数据库获取一次
            List<String> serialNums = iPropertyRepairManageClient.getRepairNums(timeNum);
            // 数据库中没有，则当天第一次开始
            if (serialNums == null || serialNums.isEmpty()) {
                // 先以全局唯一的userId对当前value进行加密，userId实现动态
                redisService.set(key, RedisConstant.REPAIR_SERIAL_NUM_TIME, 1 + "_" + userId);
                repairNum = timeNum + StringHandlerUtil.formatStrLen("1","0",5,false,false);
                // 获取加密后的value
                String userIdValue = redisService.get(key);
                // 加密后的value与一开始加密的value相等，则完成此次获取,并设置下次可用的流水号
                if ((1 + "_" + userId).equals(userIdValue)) {
                    redisService.set(key, RedisConstant.REPAIR_SERIAL_NUM_TIME, "2");
                    return repairNum;
                } else {
                    // 失败了之后再重新拿
                    return getRepairProcessSerialNum(userId,nowTime);
                }
            } else {
                // 数据库中有，则流水号从数据库中最大值+1开始
                int num = 0;
                for (String serialNum : serialNums){
                    String substring = serialNum.substring(serialNum.length() - 5, serialNum.length());
                    int i = StringHandlerUtil.strToIntDef(substring, 0);
                    if (i > num){
                        num = i;
                    }
                }
                redisService.set(key, RedisConstant.REPAIR_SERIAL_NUM_TIME, num + "_" + userId);
                repairNum = timeNum + NumberHandlerUtil.numFormatToString(++num,5);
                if ((--num + "_" + userId).equals(redisService.get(key))) {
                    num += 2;
                    redisService.set(key,RedisConstant.REPAIR_SERIAL_NUM_TIME,num + "");
                    return repairNum;
                } else {
                    return getRepairProcessSerialNum(userId,nowTime);
                }
            }
        } else { // 缓存中已经有今天的流水号
            if (StringHandlerUtil.strToIntDef(value,0) != 0) { // value可解析，非加密后的
                // 先以全局唯一的userId对当前value进行加密，userId实现动态
                redisService.set(key, RedisConstant.REPAIR_SERIAL_NUM_TIME, value + "_" + userId);
                repairNum = timeNum + StringHandlerUtil.formatStrLen(value,"0",5,false,false);
                // 获取加密后的value
                String userIdValue = redisService.get(key);
                // 加密后的value与一开始加密的value相等，则完成此次获取,并设置下次可用的流水号
                if ((value + "_" + userId).equals(userIdValue)) {
                    int num = StringHandlerUtil.strToIntDef(value, 0) + 1;
                    redisService.set(key, RedisConstant.REPAIR_SERIAL_NUM_TIME, num + "");
                    return repairNum;
                } else {
                    // 失败了之后再重新拿
                    return getRepairProcessSerialNum(userId,nowTime);
                }
            } else { // 不可解析，则继续拿
                return getRepairProcessSerialNum(userId,nowTime);
            }
        }
    }


    /**
     * <desc>
     *      获取账单详情,返回最新账单
     * </desc>
     *
     * @param appServiceGetAccountDetailDTO 获取账单详情DTO
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/16
     */
    @PostMapping("getAccountDetail")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_GET_REPAIR_DETAIL)
    public Object getAccountDetail(APPServiceGetAccountDetailDTO appServiceGetAccountDetailDTO){
        try {
            boolean flag1 = StringUtils.isNotBlank(appServiceGetAccountDetailDTO.getCreateTime());
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                appServiceGetAccountDetailDTO = HttpProtocolUtil.parseRequestParamToDTO(APPServiceGetAccountDetailDTO.class, request);
            }
            if (StringUtils.isBlank(appServiceGetAccountDetailDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("feeId", appServiceGetAccountDetailDTO.getFeeId());
            params.put("projectId", appServiceGetAccountDetailDTO.getProjectId());
            params.put("roomId", appServiceGetAccountDetailDTO.getRoomId());
            params.put("year", appServiceGetAccountDetailDTO.getYear());
            params.put("month", appServiceGetAccountDetailDTO.getMonth());
            params.put("language", appServiceGetAccountDetailDTO.getLanguage());
            params.put("createTime", appServiceGetAccountDetailDTO.getCreateTime());
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, appServiceGetAccountDetailDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, appServiceGetAccountDetailDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            AppUserCacheVO userInfo=userCache.retrieve(appServiceGetAccountDetailDTO.getToken());
            AppServiceAccountDetailVO result =
                    iPropertyAccountServiceClient.getAccountDetailForAPP(appServiceGetAccountDetailDTO,userInfo.getUserId());
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), result);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取账单详情失败",e);
        }
    }

    /**
     * <desc>
     *      分页获取账单列表
     * </desc>
     *
     * @param appServiceGetAccountPageDTO 获取账单列表DTO
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/08/21
     */
    @PostMapping("getAccountBypage")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_GET_REPAIR_DETAIL)
    public Object getAccountBypage(APPServiceGetAccountPageDTO appServiceGetAccountPageDTO){
        try {
            boolean flag1 = StringUtils.isNotBlank(appServiceGetAccountPageDTO.getCreateTime());
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                appServiceGetAccountPageDTO = HttpProtocolUtil.parseRequestParamToDTO(APPServiceGetAccountPageDTO.class, request);
            }
            if (StringUtils.isBlank(appServiceGetAccountPageDTO.getProjectId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (StringUtils.isBlank(appServiceGetAccountPageDTO.getRoomId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("projectId", appServiceGetAccountPageDTO.getProjectId());
            params.put("roomId", appServiceGetAccountPageDTO.getRoomId());
            params.put("year", appServiceGetAccountPageDTO.getYear());
            params.put("month", appServiceGetAccountPageDTO.getMonth());
            params.put("currentPage", appServiceGetAccountPageDTO.getCurrentPage());
            params.put("pageSize", appServiceGetAccountPageDTO.getPageSize());
            params.put("language", appServiceGetAccountPageDTO.getLanguage());
            params.put("createTime", appServiceGetAccountPageDTO.getCreateTime());
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, appServiceGetAccountPageDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, appServiceGetAccountPageDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            AppUserCacheVO userInfo = userCache.retrieve(appServiceGetAccountPageDTO.getToken());
            Page<AppServiceAccountInfoALLVO> result =
                    iPropertyAccountServiceClient.getAccountBypageForAPP(appServiceGetAccountPageDTO, userInfo.getUserId());
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), result);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取账单列表失败",e);
        }
    }


    /**
     * <desc>
     * 获取临时车辆列表
     * </desc>
     *
     * @param appServiceTemporaryCarListPageDTO
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/11/06
     */
    @PostMapping("temporaryCarList")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_TEMPORARY_CAR_LIST)
    public Object temporaryCarList(APPServiceTemporaryCarListPageDTO appServiceTemporaryCarListPageDTO) {
        try{
            boolean flag1 = StringUtils.isNotBlank(appServiceTemporaryCarListPageDTO.getCreateTime());
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                appServiceTemporaryCarListPageDTO = HttpProtocolUtil.parseRequestParamToDTO(APPServiceTemporaryCarListPageDTO.class, request);
            }
            if(StringUtils.isEmpty(appServiceTemporaryCarListPageDTO.getToken())){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("currentPage",appServiceTemporaryCarListPageDTO.getCurrentPage());
            params.put("pageSize",appServiceTemporaryCarListPageDTO.getPageSize());
            params.put("language",appServiceTemporaryCarListPageDTO.getLanguage());
            params.put("createTime",appServiceTemporaryCarListPageDTO.getCreateTime());
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,appServiceTemporaryCarListPageDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(appServiceTemporaryCarListPageDTO.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,appServiceTemporaryCarListPageDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(appServiceTemporaryCarListPageDTO.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            AppUserCacheVO userInfo=userCache.retrieve(appServiceTemporaryCarListPageDTO.getToken());
            appServiceTemporaryCarListPageDTO.setUserId(userInfo.getUserId());
            Page<AppServiceTemporaryCarListVO> result =
                    iPropertyCarMonthCardServiceClient.temporaryCarList(appServiceTemporaryCarListPageDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),result.getRows());
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】获取临时车辆列表失败",e);
        }
    }

    /**
     * <desc>
     * 删除临时车辆列表
     * </desc>
     *
     * @param plateNumber 车牌
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/11/06
     */
    @PostMapping("deleteTemporaryCar")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_DELETE_TEMPORARY_CAR_LIST)
    public Object deleteTemporaryCar(String plateNumber, String token, String createTime, String sign, String language) {
        try{
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                plateNumber = request.getAttribute("plateNumber") == null ? null : request.getAttribute("plateNumber").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            if(StringUtils.isEmpty(token)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("plateNumber",plateNumber);
            params.put("language",language);
            params.put("createTime",createTime);
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            AppUserCacheVO userInfo=userCache.retrieve(token);
            iPropertyCarMonthCardServiceClient.deleteTemporaryCar(plateNumber,userInfo.getUserId());
            return new MessageVO(plateNumber,BaseErrorCodeEnum.SUCCESS.getErrorCode());
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】删除临时车辆列表失败",e);
        }
    }

    /**
     * <desc>
     *      清除临时车辆列表
     * </desc>
     *
     * @return MessageVO 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/06/25
     */
    @PostMapping("deleteAllTemporaryCar")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_DELETE_ALL_TEMPORARY_CAR_LIST)
    public Object deleteAllTemporaryCar(String token, String createTime, String sign, String language) {
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            if(StringUtils.isEmpty(token)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("language",language);
            params.put("createTime",createTime);
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }

            AppUserCacheVO userInfo=userCache.retrieve(token);
            iPropertyCarMonthCardServiceClient.deleteAllTemporaryCar(userInfo.getUserId());
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】清除临时车辆列表失败",e);
        }
    }

    /**
     * <desc>
     * 生成临时车辆停车账单
     * </desc>
     *
     * @param appServiceTemporaryCarBillDTO 生成账单必要信息
     * @return MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2018/11/07
     */
    @PostMapping("temporaryCarBill")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_CREATE_CAR_BILL)
    public Object temporaryCarBill(APPServiceTemporaryCarBillDTO appServiceTemporaryCarBillDTO) {
        try {
            boolean flag1 = StringUtils.isNotBlank(appServiceTemporaryCarBillDTO.getCreateTime());
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                appServiceTemporaryCarBillDTO = HttpProtocolUtil.parseRequestParamToDTO(APPServiceTemporaryCarBillDTO.class, request);
            }
            if (StringUtils.isEmpty(appServiceTemporaryCarBillDTO.getToken())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (StringUtils.isEmpty(appServiceTemporaryCarBillDTO.getPlateNumber())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String, String> params = new HashMap<>();
            params.put("plateNumber", appServiceTemporaryCarBillDTO.getPlateNumber());
            params.put("redeemCode", appServiceTemporaryCarBillDTO.getRedeemCode());
            params.put("isCoupon", appServiceTemporaryCarBillDTO.getIsCoupon());
            params.put("language", appServiceTemporaryCarBillDTO.getLanguage());
            params.put("createTime", appServiceTemporaryCarBillDTO.getCreateTime());
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, appServiceTemporaryCarBillDTO.getSign(), APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    return new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, appServiceTemporaryCarBillDTO.getSign(), APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    return new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }

            AppServiceTemporaryCarBillVO checkResult = iPropertyAccountServiceClient.checkCarBill(appServiceTemporaryCarBillDTO);
            //判断车辆是否进场
            if ("0".equals(checkResult.getIsParkingFlag())) {
                return new MessageVO(AppErrorCodeEnum.CAR_IS_NOT_PARKING_ERR.getErrorCode());
            }
            //判断车辆是否是月卡用户
            if ("0".equals(checkResult.getMoonCarFlag())) {
                return new MessageVO(AppErrorCodeEnum.MOON_CARD_IS_NOT_OVERDUE_ERR.getErrorCode());
            }
            //判断项目是否禁用
            if (!"1".equals(checkResult.getStatus())) {
                return new MessageVO(AppErrorCodeEnum.PAD_PROJECT_FORBIDDEN.getErrorCode());
            }

            AppUserCacheVO userInfo = userCache.retrieve(appServiceTemporaryCarBillDTO.getToken());
            //获取停车金额
            NettyServiceDTO nettyServiceDTO =
                    iPropertyAccountServiceClient.calculationAmount(
                            appServiceTemporaryCarBillDTO.getPlateNumber(),appServiceTemporaryCarBillDTO.getRedeemCode(),checkResult.getProjectId());
            ParkingMessageDTO parkingMessageDTO = iNettyServiceClient.synOrderByParking(
                    nettyServiceDTO.getClientKey(),nettyServiceDTO.getContent(),nettyServiceDTO.getParkingBusinessOrderEnum(),nettyServiceDTO.getMessageId());
            ResultMessageDTO dto = JsonUtil.decode(parkingMessageDTO.getContent(), new TypeReference<ResultMessageDTO>() {});

            if (!"0".equals(dto.getCode().toString())) {
                return new MessageVO(AppErrorCodeEnum.GET_PARKING_ACCOUNT_ERR.getErrorCode());
            }
            appServiceTemporaryCarBillDTO.setAccount(new BigDecimal(dto.getMessage()));

            NettyServiceDTO nettyServiceDTO2 =
                    iPropertyAccountServiceClient.calculationAmount(
                            appServiceTemporaryCarBillDTO.getPlateNumber(),"",checkResult.getProjectId());

            ParkingMessageDTO parkingMessageDTO2 = iNettyServiceClient.synOrderByParking(
                    nettyServiceDTO2.getClientKey(),nettyServiceDTO2.getContent(),nettyServiceDTO2.getParkingBusinessOrderEnum(),nettyServiceDTO2.getMessageId());
            ResultMessageDTO dto2 = JsonUtil.decode(parkingMessageDTO2.getContent(), new TypeReference<ResultMessageDTO>() {});
            appServiceTemporaryCarBillDTO.setAccountOld(new BigDecimal(dto2.getMessage()));

            AppServiceTemporaryCarBillVO result = iPropertyAccountServiceClient.temporaryCarBill(appServiceTemporaryCarBillDTO, userInfo.getUserId());
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), result);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】生成临时车辆停车账单失败", e);
        }
    }

    /**
     * <desc>
     *      获取月卡车辆列表
     * </desc>
     *
     * @param token
     * @return MessageVO 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2018/11/06
     */
    @ResponseBody
    @PostMapping(path = "/monCarList")
    public Object getMonthCarList(String token,String sign,String language,String createTime){
        try{
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            if(StringUtils.isEmpty(token)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("language",language);
            params.put("createTime",createTime);
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            String userId = UserTokenUtil.newAPPTokenDecrypt(token,APP_USER_TOKEN_KEY);
            List<AppMonthCardParkingVO> list = iAppMonthCardParkingServiceClient.getMonthCarList(userId);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),list);
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】获取月卡车辆列表失败",e);
        }
    }

    /**
     * <desc>
     *      获取当前用户是否是月卡用户
     * </desc>
     *
     * @param token
     * @return MessageVO 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2018/11/06
     */
    @ResponseBody
    @PostMapping(path = "/isParkVIP")
    public Object getUserIsParkVIP(String token,String sign,String language,String createTime){
        try{
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            if(StringUtils.isEmpty(token)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("language",language);
            params.put("createTime",createTime);
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            String userId = UserTokenUtil.newAPPTokenDecrypt(token,APP_USER_TOKEN_KEY);
            Map<String,String> map = new HashMap<>();
            if (iAppMonthCardParkingServiceClient.getUserIsParkVIP(userId) > 0) {
                map.put("isVip", "1");
            } else {
                map.put("isVip", "2");
            }
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),map);
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】获取当前用户是否是月卡用户失败",e);
        }
    }

    /**
     * <desc>
     *      生成月卡车辆缴费账单
     * </desc>
     *
     * @param appMonthCarBillDTO 生成账单所需参数
     * @return MessageVO 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2018/11/07
     */
    @ResponseBody
    @PostMapping(path = "/monCarBill")
    @LoggerInfo(operateDesc = LogDescConstant.APP_MONTH_CAR_FEE_BILL)
    public Object monCarFeeBill(AppMonthCarBillDTO appMonthCarBillDTO){
       try{
           boolean flag1 = StringUtils.isNotBlank(appMonthCarBillDTO.getCreateTime());
           if (!flag1) {
               HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
               appMonthCarBillDTO = HttpProtocolUtil.parseRequestParamToDTO(AppMonthCarBillDTO.class, request);
           }
           // 验签
           Map<String,String> params = new HashMap<>();
           params.put("language",appMonthCarBillDTO.getLanguage());
           params.put("createTime",appMonthCarBillDTO.getCreateTime());
           params.put("carId",appMonthCarBillDTO.getCarId());
           params.put("projectId",appMonthCarBillDTO.getProjectId());
           params.put("month",appMonthCarBillDTO.getMonth());
           params.put("billId",appMonthCarBillDTO.getBillId());
           if (flag1) {
               if(!Md5EncryptUtil.checkAppSign(params,appMonthCarBillDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                   ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(appMonthCarBillDTO.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                   return new MessageVO(errorCode);
               }
           } else {
               if(!Md5EncryptUtil.checkAppSignValue(params,appMonthCarBillDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                   ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(appMonthCarBillDTO.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                   return new MessageVO(errorCode);
               }
           }
           if(StringUtils.isEmpty(appMonthCarBillDTO.getCarId()) || StringUtils.isEmpty(appMonthCarBillDTO.getProjectId())){
               return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
           }
           AppMonthCardBillVO billVO = iAppMonthCardParkingServiceClient.monCarFeeBill(appMonthCarBillDTO);
           return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),billVO);
       }catch (Exception e){
           throw new DataAccessException("【APP_服务】生成月卡车辆缴费账单失败",e);
       }
    }

    /**
     * <desc>
     *      获取当前用户下月卡车辆缴费账单列表
     * </desc>
     *
     * @param recordPageDTO 获取账单所需参数
     * @return MessageVO 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2018/11/08
     */
    @ResponseBody
    @PostMapping(path = "/monPayList")
    public Object getMonPayListPage(AppMonthCardFeeRecordPageDTO recordPageDTO){
        try{
            boolean flag1 = StringUtils.isNotBlank(recordPageDTO.getCreateTime());
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                recordPageDTO = HttpProtocolUtil.parseRequestParamToDTO(AppMonthCardFeeRecordPageDTO.class, request);
            }
            // 验签
            Map<String,String> params = new HashMap<>();
            params.put("language",recordPageDTO.getLanguage());
            params.put("createTime",recordPageDTO.getCreateTime());
            params.put("pageNum",recordPageDTO.getPageNum());

            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,recordPageDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(recordPageDTO.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,recordPageDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(recordPageDTO.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            String userId = UserTokenUtil.newAPPTokenDecrypt(recordPageDTO.getToken(),APP_USER_TOKEN_KEY);
            recordPageDTO.setUserId(userId);
            recordPageDTO.setPageSize("15");
            List<AppMonthCardFeeRecordVO> list = iAppMonthCardParkingServiceClient.getMonPayListPage(recordPageDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),list);
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】获取当前用户下月卡车辆缴费账单列表失败",e);
        }
    }

    /**
     * <desc>
     *      获取优惠券列表
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wanghzi
     * @createDate 2018/11/09
     */
    @ResponseBody
    @PostMapping(path = "/couponsList")
    public Object getCouponList(String token,String sign, String language,String createTime,String projectId, String type){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                type = request.getAttribute("type") == null ? null : request.getAttribute("type").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            // 验签
            Map<String, String> params = new HashMap<>();
            params.put("projectId",projectId);
            params.put("type",type);
            params.put("language",language);
            params.put("createTime",createTime);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            AppUserCacheVO userInfo = userCache.retrieve(token);
            if (userInfo == null){
                throw new Exception("从缓存中获取用户信息失败");
            }
            List<AppGetCouponListVO> appGetCouponListVOList = iAppCouponServiceClient.getCouponList(userInfo.getPhoneNo(), projectId, null, type);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), appGetCouponListVOList);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取优惠券列表失败",e);
        }
    }

    /**
     * <desc>
     *      添加(兑换)优惠券
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wanghzi
     * @createDate 2018/11/09
     */
    @ResponseBody
    @PostMapping(path = "/addCoupons")
    @LoggerInfo(operateDesc = LogDescConstant.APP_USER_REDEEM_COUPON_LOG_DESC)
    public Object addCouponsByRedeemCode(String token, String sign, String language, String createTime, String redeemCode){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                redeemCode = request.getAttribute("redeemCode") == null ? null : request.getAttribute("redeemCode").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            // 验签
            Map<String, String> params = new HashMap<>();
            params.put("language",language);
            params.put("createTime",createTime);
            params.put("redeemCode",redeemCode);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            // 处理一下优惠券兑换码，可能是二维码扫出来的
            redeemCode = redeemCode.substring(redeemCode.indexOf("=") + 1,redeemCode.length());
            AppUserCacheVO userInfo = userCache.retrieve(token);
            if (userInfo == null){
                throw new Exception("从缓存中获取用户信息失败");
            }
            // 验证该优惠券是否可用
            PropertyParkCouponPO propertyParkCouponPO = iAppCouponServiceClient.getCouponByRedeemCode(redeemCode);
            if (propertyParkCouponPO == null) {
                return new MessageVO(AppErrorCodeEnum.COUPON_NOT_EXIST_ERR.getErrorCode());
            }
            if (propertyParkCouponPO.getRedeemStatus() == 2) {
                return new MessageVO(AppErrorCodeEnum.COUPON_REDEEM_STATUS_ERR.getErrorCode());
            }
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date endTime = simpleDateFormat.parse(simpleDateFormat.format(propertyParkCouponPO.getEndTime()));
            Date nowTime = simpleDateFormat.parse(simpleDateFormat.format(new Date()));
            if (endTime.compareTo(nowTime) < 0) {
                return new MessageVO(AppErrorCodeEnum.COUPON_END_TIME_GONE_ERR.getErrorCode());
            }
            propertyParkCouponPO.setRedeemUser(userInfo.getUserId());
            propertyParkCouponPO.setPhoneNum(userInfo.getPhoneNo());
            propertyParkCouponPO.setRedeemStatus(2);
            propertyParkCouponPO.setUpdateTime(new Date());
            AppGetCouponListVO appGetCouponListVO = iAppCouponServiceClient.addCoupons(propertyParkCouponPO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),appGetCouponListVO);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】添加优惠券失败",e);
        }
    }

    /**
     * <desc>
     *      获取用户停车记录列表
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wanghzi
     * @createDate 2018/11/09
     */
    @ResponseBody
    @PostMapping(path = "/parkingList")
    public Object getParkingList(AppGetParkingListDTO appGetParkingListDTO){
        try {
            boolean flag1 = StringUtils.isNotBlank(appGetParkingListDTO.getCreateTime());
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                appGetParkingListDTO = HttpProtocolUtil.parseRequestParamToDTO(AppGetParkingListDTO.class, request);
            }
            if (appGetParkingListDTO == null) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            // 验签
            Map<String, String> params = new HashMap<>();
            params.put("language",appGetParkingListDTO.getLanguage());
            params.put("createTime",appGetParkingListDTO.getCreateTime());
            params.put("isTemp",appGetParkingListDTO.getIsTemp());
            params.put("carNum",appGetParkingListDTO.getCarNum());
            params.put("date",appGetParkingListDTO.getDate());
            params.put("pageNum",appGetParkingListDTO.getPageNum());
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params,appGetParkingListDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(appGetParkingListDTO.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params,appGetParkingListDTO.getSign(),APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(appGetParkingListDTO.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            AppUserCacheVO userInfo=userCache.retrieve(appGetParkingListDTO.getToken());
            appGetParkingListDTO.setUserId(userInfo.getUserId());
            AppGetParkingListVO appGetParkingListVO = iAppParkRecordServiceClient.getParkingList(appGetParkingListDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),StringHandlerUtil.formatString(appGetParkingListVO));
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取用户停车记录列表失败",e);
        }
    }

    /**
     * <desc>
     *      获取该用户停车记录列表有效查询时间
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wanghzi
     * @createDate 2018/11/09
     */
    @ResponseBody
    @PostMapping(path = "/parkingDateList")
    public Object getParkingDateList(String token, String sign, String language, String createTime, String carNum){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                carNum = request.getAttribute("carNum") == null ? null : request.getAttribute("carNum").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            // 验签
            Map<String, String> params = new HashMap<>();
            params.put("language",language);
            params.put("createTime",createTime);
            params.put("carNum",carNum);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            AppUserCacheVO userInfo=userCache.retrieve(token);
            List<AppGetParkingDateVO> appGetParkingDateVOList = iAppParkRecordServiceClient.getParkingDateList(carNum,userInfo.getUserId());
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),StringHandlerUtil.formatString(appGetParkingDateVOList));
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取该用户停车记录列表有效查询时间失败",e);
        }
    }

    /**
     * <desc>
     *      获取该用户车辆缴费明细
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wanghzi
     * @createDate 2018/11/12
     */
    @ResponseBody
    @PostMapping(path = "/payDetail")
    public Object getCarPayDetail(String token, String sign, String language, String createTime, String recordId){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                recordId = request.getAttribute("recordId") == null ? null : request.getAttribute("recordId").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            // 验签
            Map<String, String> params = new HashMap<>();
            params.put("language",language);
            params.put("createTime",createTime);
            params.put("recordId",recordId);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            if (StringUtils.isBlank(recordId)) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            AppGetCarPaymentDetailVO appGetCarPaymentDetailVO = iAppCarPaymentDetailServiceClient.getCarPayDetail(recordId);
            appGetCarPaymentDetailVO = (AppGetCarPaymentDetailVO)StringHandlerUtil.formatString(appGetCarPaymentDetailVO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),appGetCarPaymentDetailVO);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取该用户车辆缴费明细失败",e);
        }
    }

    /**
     * <desc>
     *      处理零元支付
     * <desc/>
     *
     * @param
     * @return  标准化响应结果
     * @author Juguang.S
     * @createDate 2018/11/15
     */
    @ResponseBody
    @RequestMapping("/zeroPayment")
    public Object zeroPayment(String billsId, String token, String createTime,String sign,String language,String feeType) {
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                billsId = request.getAttribute("billsId") == null ? null : request.getAttribute("billsId").toString();
                feeType = request.getAttribute("feeType") == null ? null : request.getAttribute("feeType").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("feeType",feeType);
            params.put("billsId",billsId);
            params.put("createTime",createTime);
            params.put("language",language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }else if (StringUtils.isBlank(token)||StringUtils.isBlank(billsId)||StringUtils.isBlank(feeType)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }else if (StringUtils.isBlank(token)||StringUtils.isBlank(billsId)||StringUtils.isBlank(feeType)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            //查询该账单是否已经被完成
            if(wechatPayServiceClient.getBillStatus(billsId)>0){
                return new MessageVO(AppErrorCodeEnum.BILL_PAY_SUCCESS.getErrorCode());
            }

            iAppMonthCardParkingServiceClient.noticeZeroPayment(billsId);
            AppPayParkFeeNoticeVO payParkFeeNoticeVO = wechatPayServiceClient.getZeroPaymentNotice(billsId);
            //处理临时停车缴费通知
            NettyServiceDTO nettyServiceDTO = parkCarHttpServiceClient.paymentParkFee(payParkFeeNoticeVO.getParkingCostsDTO());
            String projectId = payParkFeeNoticeVO.getParkingCostsDTO().getProjectId();
            try{
                iNettyServiceClient.synOrderByParking(nettyServiceDTO.getClientKey(),nettyServiceDTO.getContent(),nettyServiceDTO.getParkingBusinessOrderEnum(),nettyServiceDTO.getMessageId());
            }catch (Exception e){
                //返回失败则将requestContent放入队列进行处理
                wechatPayServiceClient.sendMessager(projectId,nettyServiceDTO.getContent(),ParkingOrderTypeEnum.PAYMENT_PARKING_FEE.getType());
            }


            Map<String,Object> map = new HashMap<>();
            map.put("paymentStatus","2");
            map.put("balance",0.00);
            map.put("remark","支付成功");

            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),map);
        } catch (Exception e) {
            throw new DataAccessException("【App_zeroPayment】处理零元支付失败", e);
        }
    }

    /**
     * <desc>
     *      获取当前房屋列表，app2.0版本新增
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/06/27
     */
    @ResponseBody
    @PostMapping("getHomeList")
    public Object getHomeList(String projectId, String token, String createTime, String sign, String language) {
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String, String> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("createTime", createTime);
            params.put("language", language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }

            if (StringUtils.isBlank(projectId) || StringUtils.isBlank(token)) {
                return new MessageVO(LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.NOT_PARAM.getErrorCode() : BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode());
            }
            // 从缓存中获取用户信息
            AppUserCacheVO userInfo = (AppUserCacheVO) StringHandlerUtil.formatString(userCache.retrieve(token));
            Map<String, Object> data = iAppRoomServiceClient.getHomeList(projectId, userInfo.getUserId());
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.SUCCESS.getErrorCode() : BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return new MessageVO(errorCode, data);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取当前房屋列表失败", e);
        }
    }

    /**
     * <desc>
     *      获取乘梯套餐列表
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/06/27
     */
    @ResponseBody
    @PostMapping("getLiftPayMenu")
    public Object getLiftPayMenu(String projectId, String roomId, String createTime, String sign, String language) {
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                roomId = request.getAttribute("roomId") == null ? null : request.getAttribute("roomId").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String, String> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("roomId", roomId);
            params.put("createTime", createTime);
            params.put("language", language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }

            if (StringUtils.isBlank(projectId) || StringUtils.isBlank(roomId)) {
                return new MessageVO(LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.NOT_PARAM.getErrorCode() : BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode());
            }
            AppElevatorMealVO vo = new AppElevatorMealVO();
            List<AppElevatorMealInfoVO> mealList = iPropertyMealManageServiceClient.getMealManageByProjectId(projectId,roomId);
            vo.setMealList(mealList);
            vo.setPassCount(iPropertyRoomInfoServiceClient.getRoomLastCountByRoomId(roomId));
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.SUCCESS.getErrorCode() : BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return new MessageVO(errorCode, vo);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取乘梯缴费套餐列表失败", e);
        }
    }

    /**
     * <desc>
     *      获取乘梯缴费记录列表
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/06/27
     */
    @ResponseBody
    @PostMapping("getLiftPayRecord")
    public Object getLiftPayRecord(String projectId, String roomId, String pageNum, String consumeTime, String createTime, String sign, String language) {
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                roomId = request.getAttribute("roomId") == null ? null : request.getAttribute("roomId").toString();
                consumeTime = request.getAttribute("consumeTime") == null ? null : request.getAttribute("consumeTime").toString();
                pageNum = request.getAttribute("pageNum") == null ? null : request.getAttribute("pageNum").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String, String> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("roomId", roomId);
            params.put("pageNum", pageNum);
            params.put("consumeTime", consumeTime);
            params.put("createTime", createTime);
            params.put("language", language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }

            if (StringUtils.isBlank(projectId) || StringUtils.isBlank(roomId) || StringUtils.isBlank(pageNum)) {
                return new MessageVO(LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.NOT_PARAM.getErrorCode() : BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode());
            }
            List<AppElevatorMealPayRecordVO> mealList = iPropertyPaymentServiceClient.getLiftPayRecord(projectId,roomId,pageNum,consumeTime);
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.SUCCESS.getErrorCode() : BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return new MessageVO(errorCode, mealList);
        } catch (Exception e) {
            throw new DataAccessException("【APP_服务】获取乘梯缴费记录列表失败", e);
        }
    }

    /**
     * <desc>
     *      获取消费记录
     * </desc>
     *
     * @param appConsumeRecordDTO app消费记录参数DTO
     * @return
     * @Author Zhu.yj
     * @createDate  2020/7/17
     */
    @RequestMapping(value = "getLiftConsumeRecord", method = RequestMethod.POST)
    public Object getLiftConsumeRecord(AppConsumeRecordDTO appConsumeRecordDTO, String createTime, HttpServletRequest request){
        try{
            boolean flag = StringUtils.isNotBlank(createTime);
            if (!flag){
                appConsumeRecordDTO = HttpProtocolUtil.parseRequestParamToDTO(AppConsumeRecordDTO.class, request);
            }
            Map<String, String> params = new HashMap<>();
            params.put("projectId", appConsumeRecordDTO.getProjectId());
            params.put("roomId", appConsumeRecordDTO.getRoomId());
            params.put("pageNum", appConsumeRecordDTO.getPageNum());
            params.put("consumeTime", appConsumeRecordDTO.getConsumeTime());
            params.put("userType", appConsumeRecordDTO.getUserType());
            params.put("createTime", appConsumeRecordDTO.getCreateTime());
            params.put("language", appConsumeRecordDTO.getLanguage());
            if (flag) {
                if (!Md5EncryptUtil.checkAppSign(params, appConsumeRecordDTO.getSign(), APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(appConsumeRecordDTO.getLanguage()) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, appConsumeRecordDTO.getSign(), APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(appConsumeRecordDTO.getLanguage()) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            if ( StringUtils.isBlank(appConsumeRecordDTO.getProjectId()) || StringUtils.isBlank(appConsumeRecordDTO.getRoomId())
                    || StringUtils.isBlank(appConsumeRecordDTO.getPageNum()) || StringUtils.isBlank(appConsumeRecordDTO.getUserType())){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            List<AppElevatorConsumptionRecordVO> list = iPropertyConsumptionServiceClient.getLiftConsumeRecord(appConsumeRecordDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), list);
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】获取消费记录列表失败", e);
        }
    }

    /**
     * <desc>
     *      获取有记录的年、月
     * </desc>
     *
     * @return
     * @Author Zhu.yj
     * @createDate  2020/7/20
     */
    @RequestMapping(value = "getLiftDateRecord", method = RequestMethod.POST)
    public Object getLiftDateRecord(AppConsumeRecordDTO appConsumeRecordDTO, String createTime, HttpServletRequest request){
        try{
            boolean flag = StringUtils.isNotBlank(createTime);
            if (!flag){
                appConsumeRecordDTO = HttpProtocolUtil.parseRequestParamToDTO(AppConsumeRecordDTO.class, request);
            }
            Map<String, String> params = new HashMap<>();
            params.put("projectId", appConsumeRecordDTO.getProjectId());
            params.put("roomId", appConsumeRecordDTO.getRoomId());
            params.put("type", appConsumeRecordDTO.getType());
            params.put("createTime", appConsumeRecordDTO.getCreateTime());
            params.put("language", appConsumeRecordDTO.getLanguage());
            if (flag) {
                if (!Md5EncryptUtil.checkAppSign(params, appConsumeRecordDTO.getSign(), APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(appConsumeRecordDTO.getLanguage()) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, appConsumeRecordDTO.getSign(), APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(appConsumeRecordDTO.getLanguage()) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            if (StringUtils.isBlank(appConsumeRecordDTO.getProjectId()) || StringUtils.isBlank(appConsumeRecordDTO.getRoomId()) || StringUtils.isBlank(appConsumeRecordDTO.getType())){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if(!"1".equals(appConsumeRecordDTO.getType()) && !"2".equals(appConsumeRecordDTO.getType())){
                return new MessageVO(BaseErrorCodeEnum.PARAM_ERR.getErrorCode());
            }
            List<Map<String, Object>> list =iPropertyConsumptionServiceClient.getLiftDateRecord(appConsumeRecordDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), list);
        }catch (Exception e){
            throw new DataAccessException("【APP_服务】获取有记录的日期失败", e);
        }
    }
}
